package wiiusej.apptest.generalTasks;

import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicBoolean;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import wiiusej.Wiimote;
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;

public class VolumeSpeakerTask implements Callable{

	
	private boolean speakerStatus;
	private final Wiimote myWiimote; 
	private final Logger fileLogger;
	private int event;
	
	public VolumeSpeakerTask(Wiimote wiimote, AtomicBoolean speakerStatus, int command){
		
		this.speakerStatus = speakerStatus.get();
		this.myWiimote = wiimote;
		this.event = command;
		
		
		PropertyConfigurator.configure("log4j.properties");
		this.fileLogger = Logger.getLogger("speaker");
		
		fileLogger.debug("SpeakerStatus Received: " + speakerStatus);
	}
	
	@Override
	public Integer call() throws Exception {
		
		Integer level = null;
		
		//TURN UP/DOWN THE VOLUME OF THE SPEAKER	    
	    if(event == 1 && speakerStatus){
	    	//turn up volume in one unity	
	    	level = myWiimote.turnVolumeUp();
	    	//send a sound to give feedback
	    	//myWiimote.sendSound();
	    	
	    	fileLogger.info("Turn volume UP. LEVEL: " + level);
	    	
	    }if(event == 0 && speakerStatus){
	    	//turn down volume in one unity
	    	level = myWiimote.turnVolumeDown();
	    	//send a sound to give feedback
	    	//myWiimote.sendSound();
	    	
	    	fileLogger.info("Turn volume DOWN: LEVEL: " + level);
	    }
	    
	    
	    return level;
	    
	}
	
}